<?php
/**
 * Show the feed metadata (A specific VERSION)
 *
 * @author University of London Computer Centre
 * @version 1.1.0
 * @package ArchivePress
 * @subpackage pages
 * @global ArchivePress $ArchivePress
 * @global ArchivePressLog $ArchivePressLog
 */

// globals
global $ArchivePress;
global $ArchivePressLog;

// METADATA ID
$meta_id = 0;
if(isset($_GET["meta_id"])){
    $meta_id = (int)attribute_escape($_GET["meta_id"]);
}

// GET METADATA
$metadata = $ArchivePress->getMetadata($meta_id);

if($metadata) {
    // GET FEED
    $feed = $ArchivePress->getFeed($metadata["feed_id"]);
    $name = $ArchivePress->cleanOutput($feed["name"]);

    // GET VERSION
    $logs = $ArchivePress->getMetadataChangeLog($metadata["feed_id"]);
    if(count($logs) > 0){
        $i = 0;
        foreach($logs as $log){
            if($log["id"] == $meta_id) {
                $subtitle = sprintf(__("Metadata &ldquo;Version %s&rdquo;", ARCHIVEPRESS), (count($logs) - $i));
                break;
            }
            $i++;
        }
    }


} else {
    $name = __("No Metadata found", ARCHIVEPRESS);
    $subtitle = "";
}
echo '<div class="wrap">
        <div class="icon32" id="icon-archivepress"><br /></div>
        <h2>'.$name.'
            <a class="button add-new-h2" href="admin.php?page=archivepress/pages/metadata-changelog.php&amp;feed_id='.$metadata["feed_id"].'" title="'.__("Back to Metadata ChangeLog", ARCHIVEPRESS).'" >'.__("Back to the ChangeLog", ARCHIVEPRESS).'</a>
            <span class="subtitle">'.$subtitle.'</span>
        </h2>';

echo'

        <div class="tablenav">
            <div class="clear"></div>
        </div>

        <div class="clear"></div>

        <table cellspacing="0" class="widefat post fixed">
            <thead>
                <tr>
                    <th style="" class="manage-column column-arpr_metalogdate" scope="col">'.__("Date", ARCHIVEPRESS).'</th>
                    <th style="" class="manage-column column-arpr_changelog" scope="col">'.__("Changes", ARCHIVEPRESS).'</th>
                </tr>
            </thead>

            <tfoot>
                <tr>
                    <th style="" class="manage-column column-arpr_metalogdate" scope="col">'.__("Date", ARCHIVEPRESS).'</th>
                    <th style="" class="manage-column column-arpr_changelog" scope="col">'.__("Changes", ARCHIVEPRESS).'</th>
                </tr>
            </tfoot>

            <tbody>';

// print feeds
if($metadata) {
    echo'
            <tr valign="top" class="alternate iedit">
                <td class="column-arpr_metalogdate">'.date('F jS, Y @ H:i',$ArchivePress->cleanOutput(strtotime($metadata["date_time"]))).'</td>
                <td class="column-arpr_changelog">'.$metadata["value"].'</td>
            </tr>';
} else {
    echo '<tr valign="top" class="alternate iedit" id="feed-0"><td colspan="2">'.__("No Metadata found", ARCHIVEPRESS).'</td></tr>';
}

echo'
            </tbody>
        </table>
    </div>';

?>